Navigation

  • index
  • next |
  • previous |
  • PyHowTo documentation »
  • Basic »
  • Function »

Table of Contents

Python v3.7 HowTos:

  • ----------------
  • Recursion
  • Backtracking
  • Dynamic Programming
  • Greedy
  • Sort
  • Binary Search
  • Depth First Search [DFS]
  • Breadth First Search [BFS]
  • Binary Search Tree [BST]
  • ----------------
  • Array
  • String
  • Heap
  • Stack
  • Queue
  • Tree
  • Linked List
  • Hash Table
  • Bit Manipulation
  • Two Pointers
  • Math
  • Decorator
  • ----------------
  • Basic
  • Intermediate
  • Advanced
  • Interview
  • ----------------
  • Spark
  • Tkinter
  • Turtle
  • Games
  • Web
  • ----------------
  • About
  • History

Previous topic

Check the number is prime or not

Next topic

Check whether a number is perfect or not

Quick search

Print the even numbers from a given listΒΆ

Print the even numbers from a given list.
Sample List :
[1, 2, 3, 4, 5, 6, 7, 8, 9]
Expected Result :
[2, 4, 6, 8]
def is_even_num(L):
    even_nums = []
    for n in L:
        if n % 2 == 0:
            even_nums.append(n)
    return even_nums

# test
print(is_even_num([1, 2, 3, 4, 5, 6, 7, 8, 9]))

Output:

[2, 4, 6, 8]

See also

https://www.w3resource.com/python-exercises/python-functions-exercise-10.php

Navigation

  • index
  • next |
  • previous |
  • PyHowTo documentation »
  • Basic »
  • Function »
© Copyright 2020, Sergiy Zaytsev, szaytsev@hotmail.com. Created using Sphinx 2.3.0.